﻿Public Class LoginForm1
    Public Function Crypt(ByVal Text As String) As String
        Dim strTempChar As String
        For i = 1 To Len(Text)
            If Asc(Mid$(Text, i, 1)) < 128 Then
                strTempChar = Asc(Mid$(Text, i, 1)) + 128
            ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
                strTempChar = Asc(Mid$(Text, i, 1)) - 128
            End If
            Mid$(Text, i, 1) = Chr(strTempChar)
        Next i
        Crypt = Text
    End Function

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If USUARIOTextBox.Text = "" Or SENHATextBox.Text = "" Then
            MsgBox("FAVOR INFORMAR LOGIN/SENHA")
        Else
            SENHATextBox.Text = Crypt(SENHATextBox.Text)
                LOGINTableAdapter.FillByUSUARIOSENHA(LOGINDataSet.LOGIN, USUARIOTextBox.Text, SENHATextBox.Text)
            End If
        If LOGINDataSet.Tables(0).Rows.Count > 0 Then
            If STATUSLabel1.Text = "LOGADO" Then
                MsgBox("USUÁRIO JÁ LOGADO")
            Else
                STATUSLabel1.Text = "LOGADO"
                LOGINBindingSource.EndEdit()
                Me.TableAdapterManager.UpdateAll(Me.LOGINDataSet)
                GroupBox1.Visible = True
                Me.Hide()
                Principal.Show()
            End If
        Else
            MsgBox("FAVOR VERIFICAR SEU LOGIN")
        End If
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        STATUSLabel1.Text = "DESLOGADO"
        LOGINBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.LOGINDataSet)
    End Sub

    Private Sub LoginForm1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        USUARIOTextBox.Focus()
    End Sub
End Class
